package com.wyl.mq.config;

import com.wyl.mq.publishcomfirm.MyConfirmCallback;
import com.wyl.mq.publishcomfirm.MyReturnsCallback;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @author 吴宇亮 on 2023/6/9 16:58
 */
@Component
public class MqInitializer {

    @Resource
    private RabbitTemplate rabbitTemplate;
    @Autowired
    private MyConfirmCallback myConfirmCallback;
    @Autowired
    private MyReturnsCallback myReturnsCallback;

    //依赖注入 rabbitTemplate 之后再设置它的回调对象
    @PostConstruct
    public void init() {
        rabbitTemplate.setConfirmCallback(myConfirmCallback);
        rabbitTemplate.setReturnsCallback(myReturnsCallback);
    }
}
